<template>
  <div id="box" :style="maxHeight">
    <div id="left" v-if="$route.query.hideLeftMenu !== 'true'">
      <slot name="left"> </slot>
    </div>
    <div id="resize"></div>
    <div
      id="right"
      :style="{ width: $route.query.hideLeftMenu !== 'true' ? '85%' : '99%' }"
    >
      <cm-scroll>
        <slot name="right"></slot>
      </cm-scroll>
    </div>
  </div>
</template>

<script>
export default {
  name: "change",
  data() {
    return {
      pageHeight: window.innerHeight
    };
  },
  computed: {
    maxHeight() {
      return { height: this.pageHeight - 145 + "px" };
    }
  },
  methods: {
    dragControllerDiv: function() {
      let resize = document.getElementById("resize");
      let left = document.getElementById("left");
      let right = document.getElementById("right");
      let box = document.getElementById("box");
      resize.onmousedown = function(e) {
        let startX = e.clientX;
        resize.left = resize.offsetLeft;
        document.onmousemove = function(e) {
          let endX = e.clientX;
          let moveLen = resize.left + (endX - startX);
          let maxT = box.clientWidth - resize.offsetWidth;
          if (moveLen < 150) moveLen = 360;
          if (moveLen > maxT - 800) moveLen = maxT - 800;
          resize.style.left = moveLen;
          // left.style.width = moveLen + 'px'
          left.style.width =
            Math.floor((moveLen / box.clientWidth) * 100) + "%";

          // right.style.width = (box.clientWidth - moveLen - 5) + 'px'
          right.style.width =
            Math.floor(
              ((box.clientWidth - moveLen - 5) / box.clientWidth) * 100
            ) + "%";
          console.log(
            Math.floor(
              ((box.clientWidth - moveLen - 5) / box.clientWidth) * 100
            ) + "%"
          );
        };
        document.onmouseup = function() {
          document.onmousemove = null;
          document.onmouseup = null;
          resize.releaseCapture && resize.releaseCapture();
        };
        resize.setCapture && resize.setCapture();
        return false;
      };
    }
  },
  mounted() {
    this.dragControllerDiv();
  }
};
</script>

<style scoped>
#box {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

#left {
  width: calc(15% - 10px);
  height: 100%;
  float: left;
  overflow: hidden;
  background: white;
  margin-right: 5px;
}

#resize {
  position: relative;
  width: 5px;
  height: 100%;
  cursor: w-resize;
  float: left;
}

#right {
  width: 85%;
  height: 100%;
  float: left;
  overflow: hidden;
  background: white;
}
</style>
